package com.neusoft.hospital.controller;


import com.neusoft.hospital.pojo.checkitemdetailed;
import com.neusoft.hospital.service.Checkitemdetailedservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.sound.midi.MidiSystem;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*" ,allowCredentials = "true")
@RequestMapping("/chkd")
public class ChkdController {

	@Autowired
	Checkitemdetailedservice checkitemdetailedservice;

	/*	1.select 全部数据列表(全查)
	 * http://localhost:8080/chkd/AllchkdList
	 */
	@RequestMapping("/AllchkdList")
	public Map<String, Object> AllCirList() throws Exception{
		List<checkitemdetailed> chkdList = checkitemdetailedservice.findcheckitemdetailedBySql();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("chkdlist", chkdList);
		return map;
	}

	/*	2.select  模糊查询（通过字查）
	 * 	http://localhost:8080/chkd/getchkdByName?name=血
	 */
	@RequestMapping("/getchkdByName")
	public Map<String, Object> getCirByName(HttpSession session, String name) throws Exception{
		List<checkitemdetailed> checkitemList = checkitemdetailedservice.findcheckitemdetailedByChoose(name);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("chkList", checkitemList);
		return map;
	}

    /*	3.select cireport by cirId (通过id查)
     * 	http://localhost:8080/chkd/getchkdBycdId?cdId=2
     */
	@RequestMapping("/getchkdBycdId")
	public Map<String, Object> getCirByciId(int cdId) throws Exception{
		List<checkitemdetailed> checkitemList = checkitemdetailedservice.findcheckitemdetailedList2(cdId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("chkd", checkitemList);
		return map;
	}

    //4.修改表
	//http://localhost:8080/chkd/cdIdUpdate?cdId=2&name=身高
	@RequestMapping("/cdIdUpdate")
	public Map<String, Object> doUpdate(checkitemdetailed checkitemdetailed, String enable) throws Exception{
		checkitemdetailedservice.updatecheckitemdetailed(checkitemdetailed);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		return map;
	}

	/*	5.delete(删除数据)
	 * http://localhost:8080/chkd/delBycdId?cdId=100
	 */
	@RequestMapping("/delBycdId")
	public Map<String, Object> delByciId(HttpSession session, checkitemdetailed checkitemdetailed ) throws Exception{
		int count = checkitemdetailedservice.deletecheckitemdetailed(checkitemdetailed);
		Map<String, Object> map = new HashMap<String, Object>();
		if(count>0){
			map.put("status", "1");
		} else {
			map.put("status", "0");
		}
		return map;
	}

    /*	6.数据库的增加操作(增加数据)
     * http://localhost:8080/chkd/Insetchkd?cdId=100&name=%E5%93%88&ciId=100&type=100
     */
	@RequestMapping("/Insetchkd")
	public Map<String, Object> Insetchkd(HttpSession session, checkitemdetailed checkitemdetailed) throws Exception{
        int cdId = checkitemdetailed.getCdId();
		int count = checkitemdetailedservice.insertcheckitemdetailed(checkitemdetailed);
		Map<String, Object> map = new HashMap<String, Object>();
		if(count>0){
			map.put("status", "1");
		} else {
			map.put("status", "0");
		}
		return map;
	}
}
